package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallShowSubjectTemplateReadDao;
import com.party.core.dao.write.mall.MallShowSubjectTemplateWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallShowSubjectTemplate;
import com.party.core.model.mall.MallShowSubjectTemplateQuery;
import com.party.core.service.mall.IMallShowSubjectTemplateService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Description: 商品主题模板服务
 * @Author: yangshoukun
 * @Date: 2018/4/10 15:46
 */
@Service
public class MallShowSubjectTemplateService implements IMallShowSubjectTemplateService {

    @Autowired
    private MallShowSubjectTemplateReadDao mallShowSubjectTemplateReadDao;

    @Autowired
    private MallShowSubjectTemplateWriteDao mallShowSubjectTemplateWriteDao;

    @Override
    public String insert(MallShowSubjectTemplate mallShowSubjectTemplate) {
        BaseModel.preInsert(mallShowSubjectTemplate);
        if (null == mallShowSubjectTemplate.getGoodsNum()) {
            mallShowSubjectTemplate.setGoodsNum(0);
        }
        if (null == mallShowSubjectTemplate.getOrgNum()) {
            mallShowSubjectTemplate.setOrgNum(0);
        }
        boolean result = mallShowSubjectTemplateWriteDao.insert(mallShowSubjectTemplate);
        if (result){
            return mallShowSubjectTemplate.getId();
        }
        return null;
    }

    @Override
    public boolean update(MallShowSubjectTemplate mallShowSubjectTemplate) {
        return mallShowSubjectTemplateWriteDao.update(mallShowSubjectTemplate);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowSubjectTemplateWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallShowSubjectTemplateWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return mallShowSubjectTemplateWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return mallShowSubjectTemplateWriteDao.batchDelete(ids);
    }

    @Override
    public MallShowSubjectTemplate get(String id) {
        return mallShowSubjectTemplateReadDao.get(id);
    }

    @Override
    public List<MallShowSubjectTemplate> listPage(MallShowSubjectTemplate mallShowSubjectTemplate, Page page) {
        return mallShowSubjectTemplateReadDao.listPage(mallShowSubjectTemplate, page);
    }

    @Override
    public List<MallShowSubjectTemplate> list(MallShowSubjectTemplate mallShowSubjectTemplate) {
        return listPage(mallShowSubjectTemplate, null);
    }

    @Override
    public List<MallShowSubjectTemplate> batchList(Set<String> ids, MallShowSubjectTemplate mallShowSubjectTemplate, Page page) {
        return null;
    }

    /**
     *
     * @param mallShowSubjectTemplateQuery
     * @param page
     * @return
     */
    @Override
    public List<MallShowSubjectTemplate> queryPageList(MallShowSubjectTemplateQuery mallShowSubjectTemplateQuery, Page page) {
        return mallShowSubjectTemplateReadDao.queryPageList(mallShowSubjectTemplateQuery, page);
    }
}
